<?php if (!defined('FIT_PATH')) exit('No direct script access allowed');
/**
 * @copyright 2009 - 2011 Bincent.com. All Rights Reserved.
 * @license http://www.apache.org/licenses/LICENSE-2.0
 * @package FitPHP
 * 
 * @author Hongbin Hsu <Hongbin.Hsu@gmail.com> Initial.
 * @version $Id: library/filter.php 1.0 2010-09-18 16:52 hongbin.hsu $
 */

class Library_Filter
{
	public function __construct() {
		unset($GLOBALS, $_ENV, $HTTP_GET_VARS, $HTTP_POST_VARS,
		$HTTP_COOKIE_VARS, $HTTP_SERVER_VARS, $HTTP_ENV_VARS);
		$_GET 		= $this->addslashe($_GET, 1, true);
		$_POST 		= $this->addslashe($_POST, 1, true);
		$_COOKIE 	= $this->addslashe($_COOKIE, 1, true);
		$_SERVER 	= $this->addslashe($_SERVER);
		$_FILES 	= $this->addslashe($_FILES);
		$_REQUEST 	= $this->addslashe($_REQUEST, 1, true);
	}
	
	//----------------------------------------------------------
	/**
	 * 数据过滤
	 *
	 * @param string $str
	 * @param int $force
	 * @param bool $strip
	 * @access public
	 * @return string
	 */ 
	private function addslashe($str, $force = 0, $strip = false) {
		if (!get_magic_quotes_gpc() || $force) {
			if (is_array($str)) {
	        	foreach ($str as $k => $v){
	        		$str[$k] = $this->addslashe($v, $force);
	        	}
	   		}else{
	        	$str = addslashes($strip ? stripslashes($str) : $str);
	    	}
		}
	    return $str;
	}
}